// 自定义标签
// 四个图标
var iconPath = "../../images/icons/"
var tabs = [
    {
        "icon": iconPath + "mark.png",
        "iconActive": iconPath + "markHL.png",
        "title": "日记",
        "extraStyle": "",
    },
    {
        "icon": iconPath + "collect.png",
        "iconActive": iconPath + "collectHL.png",
        "title": "收藏",
        "extraStyle": "",
    },
    {
        "icon": iconPath + "like.png",
        "iconActive": iconPath + "likeHL.png",
        "title": "喜欢",
        "extraStyle": "",
    },
    {
        "icon": iconPath + "more.png",
        "iconActive": iconPath + "moreHL.png",
        "title": "更多",
        "extraStyle": "border:none;",
    },
]
// 顶部左侧
var userInfo = {
    avatar: "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1605623818002&di=8dc5c6b0715f6b8e06ab3d499df593a6&imgtype=0&src=http%3A%2F%2Fimg.qqtouxiangzq.com%2Fkatong%2Fdudumao%2Fdudumao42.jpg",
    nickname: "今天掉头发了吗",
    //sex: "♂",  // 0, male; 1, female
    meta: '可以写日记了吗',
}


Page({

    data: {
        // 展示的tab标签
        tabs: tabs,
        // 当前选中的标签
        currentTab: "tab1",
        // 高亮的标签索引
        highLightIndex: "0",
        // 模态对话框样式 
        modalShowStyle: "",
        // 待新建的日记标题
        diaryTitle: "",
        // TODO 用户信息
        userInfo: userInfo,
    },

  

    // 点击图标触发事件
    touchTab: function(event){
        var tabIndex = parseInt(event.currentTarget.id);
        var template = "tab" + (tabIndex + 1).toString();
        wx.navigateTo({
            url: '/pages/indexQuanxian/indexQuanxian',
           })  
          this.setData({
            currentTab: template,
            highLightIndex: tabIndex.toString()
        }
        );
    },

     //日记录入
    onLoad: function (options) {   
        wx.cloud.callFunction({
          name: 'record',
          data: {
            "path": this.route,
            "query": 'index=1'
          },
          success: function (res) {
            console.log(res)
          },
          fail: function (err) {
            console.log(err)
          }
        })
      },
      async bindFormSubmit (e) {
        const { options } = e.detail.value
        if (options === '' || options === null || options === undefined) {
          wx.showToast({
            title: '请输入日记内容',
            icon: 'none',
            duration: 1500
          })
          return false
        }
        const params = {
          content: options,
          createAt: new Date(),
          updateAt: new Date(),
          status: 0, // 0未处理，1已处理
          feedback: ''
        }
        const db = wx.cloud.database()
        const res = await db.collection('myDay').add({
          data: {...params}
        })
        wx.showToast({
          title: '提交成功',
          icon: 'none',
          duration: 2000
        })
        let timmer = setTimeout(() => {
          clearTimeout(timmer)
          timmer = null
          wx.navigateBack({ delta: 3 })
        }, 2000)
      }

})
